package mp.weixin.WXpublic.send;

import mp.weixin.WXpublic.BaseReceiveMessage;
import mp.weixin.WXpublic.BaseSendMessage;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;


public class STextEntity extends BaseSendMessage {

    private String content;

    public STextEntity(BaseReceiveMessage brm, String content) {
        super(brm);
        this.content = content;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public SendTypeEnum getMsgType() {
        // TODO Auto-generated method stub
        return SendTypeEnum.TEXT;
    }

    @Override
    public String toWeiXinMessageXMLString() {
        /**
         * <xml>
         * <ToUserName><![CDATA[toUser]]></ToUserName>
         * <FromUserName><![CDATA[fromUser]]></FromUserName>
         * <CreateTime>12345678</CreateTime>
         * <MsgType><![CDATA[text]]></MsgType>
         * <Content><![CDATA[你好]]></Content>
         * </xml>
         */
//        StringBuilder xmlStr = new StringBuilder();
//        xmlStr.append("<xml>");
//        xmlStr.append("<ToUserName><![CDATA[").append(this.getToUserName()).append("]]></ToUserName>");
//        xmlStr.append("<FromUserName><![CDATA[").append(this.getFromUserName()).append("]]></FromUserName>");
//        xmlStr.append("<CreateTime>").append(this.getCreateTime().getTime()).append("</CreateTime>");
//        xmlStr.append("<MsgType><![CDATA[").append(this.getMsgType().getType()).append("]]></MsgType>");
//        xmlStr.append("<Content><![CDATA[").append(this.getContent()).append("]]></Content>");
//        xmlStr.append("</xml>");
//        return xmlStr.toString();
        String returnStr = "";
        Document doc = DocumentHelper.createDocument();
        Element rootXML = doc.addElement("xml");
        rootXML.addElement("ToUserName").setText(this.getToUserName());
        rootXML.addElement("FromUserName").setText(this.getFromUserName());
        rootXML.addElement("CreateTime").setText(this.getCreateTime().getTime() + "");
        rootXML.addElement("MsgType").setText(this.getMsgType().getType());
        rootXML.addElement("Content").setText(this.getContent());
        returnStr = rootXML.asXML();
        return returnStr;
    }

}
